<template>
<a-modal :maskClosable="false"
        :title="title"
        :width="800"
        :visible="visible"
        :confirmLoading="confirmLoading"
        @ok="handleOk"
        @cancel="handleCancel"
        cancelText="关闭">

<a-spin :spinning="confirmLoading">
   <a-form-model ref="form"  v-bind="layout"  :model="model" :rules="validatorRules">

      <a-form-model-item label="ID"  prop="id">
           <a-input placeholder="请输入ID"  v-model="model.id"  />
        </a-form-model-item >
      <a-form-model-item label="患者id" required prop="patientId">
           <a-input placeholder="请输入患者id"  v-model="model.patientId"  />
        </a-form-model-item >
      <a-form-model-item label="患者姓名" required prop="patientName">
           <a-input placeholder="请输入患者姓名"  v-model="model.patientName"  />
        </a-form-model-item >
      <a-form-model-item label="签约时间"  prop="signTime">
        <a-date-picker showTime format='YYYY-MM-DD HH:mm:ss'  v-model="model.signTime"  />
        </a-form-model-item >
      <a-form-model-item label="签订合同时间" required prop="contractTime">
        <a-date-picker showTime format='YYYY-MM-DD HH:mm:ss'  v-model="model.contractTime"  />
        </a-form-model-item >
      <a-form-model-item label="签订合同结束时间" required prop="contractEndTime">
        <a-date-picker showTime format='YYYY-MM-DD HH:mm:ss'  v-model="model.contractEndTime"  />
        </a-form-model-item >
      <a-form-model-item label="签约类型，0慢性服务  1家居病床"  prop="signType">
           <a-input placeholder="请输入签约类型，0慢性服务  1家居病床"  v-model="model.signType"  />
        </a-form-model-item >
      <a-form-model-item label="签约提供的服务id" required prop="signProjectId">
           <a-input placeholder="请输入签约提供的服务id"  v-model="model.signProjectId"  />
        </a-form-model-item >
      <a-form-model-item label="更新人员" required prop="updateUser">
           <a-input placeholder="请输入更新人员"  v-model="model.updateUser"  />
        </a-form-model-item >
      <a-form-model-item label="最近一次更新时间 " required prop="updateTime">
        <a-date-picker showTime format='YYYY-MM-DD HH:mm:ss'  v-model="model.updateTime"  />
        </a-form-model-item >
      <a-form-model-item label="创建人员 " required prop="createUser">
           <a-input placeholder="请输入创建人员 "  v-model="model.createUser"  />
        </a-form-model-item >
      <a-form-model-item label=" 注册时间" required prop="createTime">
        <a-date-picker showTime format='YYYY-MM-DD HH:mm:ss'  v-model="model.createTime"  />
        </a-form-model-item >
      <a-form-model-item label="是否已经删除，0，否；1，已删除" required prop="isDeleted">
           <a-input placeholder="请输入是否已经删除，0，否；1，已删除"  v-model="model.isDeleted"  />
        </a-form-model-item >
      <a-form-model-item label="所属医院单位组织" required prop="orgCode">
           <a-input placeholder="请输入所属医院单位组织"  v-model="model.orgCode"  />
        </a-form-model-item >
      <a-form-model-item label="租户id" required prop="tenantId">
           <a-input placeholder="请输入租户id"  v-model="model.tenantId"  />
        </a-form-model-item >
      </a-form-model>
    </a-spin>
</a-modal>
</template>

<script>
  import { httpAction,putAction,getAction,postAction} from '@/api/manage'

  export default {
    name: "hHisPatientServiceSignedModal",
    data () {
      return {
        title:"操作",
        visible: false,
        model: {},
        layout: {
           labelCol: { span: 4 },
           wrapperCol: { span: 14 },
        },
        confirmLoading: false,
        validatorRules:{
        patientId:[{ required: true, message: '请输入患者id!' }],
        patientName:[{ required: true, message: '请输入患者姓名!' }],
        contractTime:[{ required: true, message: '请输入签订合同时间!' }],
        contractEndTime:[{ required: true, message: '请输入签订合同结束时间!' }],
        signProjectId:[{ required: true, message: '请输入签约提供的服务id!' }],
        updateUser:[{ required: true, message: '请输入更新人员!' }],
        updateTime:[{ required: true, message: '请输入最近一次更新时间 !' }],
        createUser:[{ required: true, message: '请输入创建人员 !' }],
        createTime:[{ required: true, message: '请输入 注册时间!' }],
        isDeleted:[{ required: true, message: '请输入是否已经删除，0，否；1，已删除!' }],
        orgCode:[{ required: true, message: '请输入所属医院单位组织!' }],
        tenantId:[{ required: true, message: '请输入租户id!' }],
        },
        url: {
          add: "/system/hHisPatientServiceSigned",
          edit: "/system/hHisPatientServiceSigned",
        },
      }
    },
    created () {
        this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
          this.model = Object.assign({}, record);
          this.visible = true;
      },
      close () {
          this.$refs.form.clearValidate();
          this.$emit('close');
          this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
              method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                 that.$message.success(res.message);
                 that.$emit('ok');
              }else{
                 that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }else{
            return false;
         }
        })
      },
      handleCancel () {
        this.close()
      },


    }
  }
</script>

<style scoped>

</style>